package com.cn.mmd.controller;


import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * Created by Administrator on 2016/9/13 0013.
 */
/*@Controller
public class TokenController {

    @Autowired
    private StudentLService studentLService;

    @Autowired
    private TeacherLService teacherLService;

    @Autowired
    private SysRoleUserService sysRoleUserService;

    public synchronized Teacher tokenTeacher(String token, int sId, int teacherId) {
        Teacher teacher = new Teacher();
        teacher.setId(teacherId);
        teacher.setState(1);
        teacher.setSchoolId(sId);
        teacher = teacherLService.selectByTeacherNumber(teacher);
        if (teacher != null && DigestUtils.md5Hex(teacher.getId() + teacher.getPassword()).equals(token)) {
            return teacher;
        } else {
            return null;
        }
    }

    public synchronized Student tokenStudent(String token, int sId, int studentId) {
        Student student;
        student = new Student();
        student.setState(1);
        student.setSchoolId(sId);
        student.setId(studentId);
        student = studentLService.selectByStudentNumber(student);
        if (student != null && DigestUtils.md5Hex(student.getId() + student.getPassword()).equals(token)) {
            return student;
        } else {
            return null;
        }
    }*/

    //
/*    public synchronized Teacher tokenLead(int teacherId, int rId, String token, int sId) {
        if (rId == 6 || rId == 7) {
            Teacher teacher = new Teacher();
            teacher.setId(teacherId);
            teacher.setState(1);
            teacher.setSchoolId(sId);
            teacher = teacherLService.selectByTeacherNumber(teacher);
            SysRoleUser sysRoleUser = new SysRoleUser();
            sysRoleUser.setTeacherId(teacher.getId());
            sysRoleUser.setSysRoleId(rId);
            List<SysRoleUser> sysRoleUserList = sysRoleUserService.selectBy(sysRoleUser);
            if (teacher != null && DigestUtils.md5Hex(teacher.getId() + teacher.getPassword()).equals(token)
                    && sysRoleUserList.size() > 0) {
                return teacher;
            } else {
                return null;
            }
        } else {
            return null;
        }
    }
}*/
